const Subscription = require('egg').Subscription;

class TaskWeekly extends Subscription {
  // 通过 schedule 属性来设置定时任务的执行间隔等配置
  static get schedule() {
    return {
      cron: '0 0,30,57 22 * * ?',
      type: 'worker',
      env: ['pachong'],
      // immediate: true
    };
  }

  async subscribe() {
    let topics = await this.ctx.service.crawlerSvc.tianxiazuqiu();
    let result = await this.ctx.service.topicSvc.importTopics(topics);
    this.logger.info(`tianxiazuqiu ready ${topics.length} success ${result}`);
  }
}

module.exports = TaskWeekly;
